//
//  NewsCommentCell.swift
//  Jock
//
//  Created by HD on 15/3/19.
//  Copyright (c) 2015年 Haidy. All rights reserved.
//

import UIKit

class NewsCommentCell: UITableViewCell {

    @IBOutlet weak var iconView: UIImageView!
    @IBOutlet weak var nickView: UILabel!
    @IBOutlet weak var floorView: UILabel!
    @IBOutlet weak var contentLabel: UILabel!
    
    var comment: NewsComment?
    
    override func awakeFromNib() {
        super.awakeFromNib()
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
    
    func show() {
        if comment != nil {
            if let user = comment?.user {
                nickView.text = user.login
                if user.icon != nil {
                    var userIcon = user.icon
                    var userId =  user.id as NSString
                    var prefixUserId = userId.substringToIndex(4)
                    var url = "http://pic.qiushibaike.com/system/avtnew/\(prefixUserId)/\(userId)/thumb/\(userIcon)"
                    ImageLoader.loadImage(url, imageCacheDir: "iconCache", placeHolderName: "avatar.jpg", loadImageView: iconView)
                }
            } else {
                nickView.text = "匿名"
                iconView.image = UIImage(named: "avatar.jpg")
            }
            floorView.text = "\(comment!.floor)"
            contentLabel.text = comment!.content
        }
    }

}
